package demo1;

public class demo3 {
    public static void main(String[] args) throws InterruptedException {
        Thread mainT = Thread.currentThread();//拿到main线程的引用
        System.out.println(mainT.getName());

        Thread t = new Thread(()->{
            try {
                mainT.join();//main线程先结束，t线程才会继续执行
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t end");
         });
        t.start();
        Thread.sleep(2000);
        System.out.println("main end");
    }
}
